package cn.tedu.test03;

import cn.tedu.test02.Phone;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
@PropertySource(value = "classpath:user.properties",encoding = "utf-8")
public class User {
    @Value("${nickname}")
    private String nickname;
    @Value("${age}")
    private Integer age;

    @Autowired
    private Environment environment;

    public void getName(){
//        this.nickname=environment.getProperty("nickname");
        System.out.println("nickname:"+nickname);
        System.out.println("age:"+age);
        //可以从系统环境变量取值
        String name = environment.getProperty("user.name");
        System.out.println("name:"+name);
    }
}